<template>
  <div class="app-container"
       v-loading="loading">
    <el-form ref="form"
             :model="form"
             :rules="rules"
             size="small"
             label-width="180px">
      <el-form-item label="项目名称">
        <el-input v-model="form.projectName"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="客户名称">
        <el-input v-model="form.clientName"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="项目规模（万元）">
        <el-input v-model="form.scale"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="项目内容简介">
        <el-input :rows="3"
                  v-model="form.content"
                  type="textarea"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="省ICT项目编码">
        <el-input v-model="form.provinceCode"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="客户侧合同模式">
        <el-select v-model="form.customMode"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_customMode"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="合作商侧合同模式">
        <el-select v-model="form.partnerMode"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_partnerMode"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="办事处">
        <el-input v-model="form.businessOffice"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="客户经理">
        <el-input v-model="form.customerManager"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="项目类型（一级分类）">
        <el-select v-model="form.firstType"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_first_type"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="项目类型（二级分类）">
        <el-select v-model="form.secondType"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_second_type"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="行业">
        <el-select v-model="form.industry"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_industry_type"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="项目归属">
        <el-select v-model="form.attributive"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_attributive"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="项目开始支撑时间">
        <el-date-picker v-model="form.startDate"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="拓展室联系人">
        <el-input v-model="form.developmentRoomContact"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="拓展室联系人联系方式">
        <el-input v-model="form.developmentRoomContactInformation"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="是否框架支撑">
        <el-select v-model="form.isFrameSupports"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_is_frame_supports"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>

      <el-form-item label="支撑单位">
        <el-input v-model="form.supportUnit"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="是否Z类项目">
        <el-select v-model="form.ifzFlag"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_ifZ"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="是否大数据">
        <el-select v-model="form.ifBigData"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_ifBigData"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="竞争对手情况简介">
        <el-input v-model="form.competitorProfile"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="项目状态">
        <el-select v-model="form.projectStatus"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_project_status"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="合同名称">
        <el-input v-model="form.contractTitle"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="合同金额（元）">
        <el-input v-model="form.contractAmount"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="IT金额">
        <el-input v-model="form.itAmount"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="CT金额">
        <el-input v-model="form.ctAmount"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="DT金额">
        <el-input v-model="form.dtAmount"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="客户合同签订时间">
        <el-date-picker v-model="form.signingDate"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="客户合同交付期">
        <el-date-picker v-model="form.deliveryPeriodDate"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="项目完工期">
        <el-date-picker v-model="form.completionPeriodDate"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="是否及时交付">
        <el-select v-model="form.isDelivered"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_is_delivered"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="未及时交付的原因">
        <el-input :rows="3"
                  v-model="form.notDeliveredReason"
                  type="textarea"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="实施进度">
        <el-select v-model="form.implementationProgress"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_implementation_progress"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="商务进度">
        <el-select v-model="form.businessProgress"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_business_progress"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="维护要求">
        <el-input v-model="form.maintenanceRequirements"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="是否框架合作商中选">
        <el-select v-model="form.isMiddleSelection"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_is_middle_selection"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="中选合作商">
        未设置字典，请手动设置 Select
      </el-form-item>
      <el-form-item label="实施合作商">
        未设置字典，请手动设置 Select
      </el-form-item>
      <el-form-item label="实施合作商联系人">
        <el-input v-model="form.implementPartnerContact"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="实施合作商联系方式">
        <el-input v-model="form.implementPartnerContactInformation"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="转售中发文时间">
        <el-date-picker v-model="form.postingDate"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="比价纪要发布时间">
        <el-date-picker v-model="form.priceSummaryReleaseDate"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="订单归档时间">
        <el-date-picker v-model="form.orderFilingDate"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="客户侧是否有初验">
        <el-select v-model="form.isInitialTest"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_is_initial_test"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="客户侧初验时间">
        <el-date-picker v-model="form.clientInitialTestDate"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="客户侧终验时间">
        <el-date-picker v-model="form.clientFinalTestDate"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="免费维护期">
        <el-input v-model="form.freeMaintenancePeriodDate"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="维护截止日期">
        <el-date-picker v-model="form.maintenanceDeadline"
                        type="datetime"
                        style="width: 370px;" />
      </el-form-item>
      <el-form-item label="客户侧进度">
        <el-select v-model="form.customerSideProgress"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_customer_side_progress"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="合作商侧进度">
        <el-select v-model="form.partnerSideProgress"
                   filterable
                   placeholder="请选择">
          <el-option v-for="item in dict.ict_project_partner_side_progress"
                     :key="item.id"
                     :label="item.label"
                     :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="项目近期进展">
        <el-input v-model="form.recentProgress"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="下一步计划">
        <el-input v-model="form.nextPlan"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="合作商终验纪要文号">
        <el-input v-model="form.partnerFinalTestNumber"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="IT负责人">
        <el-input v-model="form.itManager"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="CT负责人">
        <el-input v-model="form.ctManager"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="DT负责人">
        <el-input v-model="form.dtManager"
                  style="width: 370px;" />
      </el-form-item>

      <el-form-item label="客户满意度">
        <el-input v-model="form.customSatisfaction"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="专业素质满意度">
        <el-input v-model="form.professionalSatisfaction"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="服务态度满意度">
        <el-input v-model="form.serviceSatisfaction"
                  style="width: 370px;" />
      </el-form-item>

      <el-form-item label="项目历史进展">
        <el-input v-model="form.historyProgree"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item label="合作商初验纪要文号">
        <el-input v-model="form.partnerInitialTestNumber"
                  style="width: 370px;" />
      </el-form-item>
      <el-form-item>
        <el-button type="info"
                   @click="cancelForm()">取消</el-button>
        <el-button :loading="loading"
                   type="primary"
                   @click="submitForm(form)">确认</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import crudIctProject from '@/api/ict/ictProject/ictProject'
import CRUD from '@crud/crud'
const defaultForm = { id: null, projectName: null, clientName: null, scale: null, content: null, firstType: null, secondType: null, industry: null, attributive: null, startDate: null, developmentRoomContact: null, developmentRoomContactInformation: null, isFrameSupports: null, supportUnit: null, competitorProfile: null, projectStatus: null, contractTitle: null, contractAmount: null, signingDate: null, deliveryPeriodDate: null, completionPeriodDate: null, isDelivered: null, notDeliveredReason: null, implementationProgress: null, businessProgress: null, maintenanceRequirements: null, isMiddleSelection: null, selectedPartner: null, implementationPartner: null, implementPartnerContact: null, implementPartnerContactInformation: null, postingDate: null, priceSummaryReleaseDate: null, orderFilingDate: null, isInitialTest: null, clientInitialTestDate: null, clientFinalTestDate: null, freeMaintenancePeriodDate: null, maintenanceDeadline: null, customerSideProgress: null, partnerSideProgress: null, recentProgress: null, nextPlan: null, partnerFinalTestNumber: null, createDate: null, createBy: null, updateDate: null, updateBy: null, submitDate: null, submitBy: null, delFlag: null, projectManager: null, annex: null, itManager: null, ctManager: null, dtManager: null, itAmount: null, ctAmount: null, dtAmount: null, ifzFlag: null, ifBigData: null, customSatisfaction: null, preScheduleAnnex: null, professionalSatisfaction: null, serviceSatisfaction: null, provinceCode: null, paymentMode: null, businessMode: null, customMode: null, partnerMode: null, businessOffice: null, isComplain: null, isFault: null, customerManager: null, historyProgree: null, partnerInitialTestNumber: null }
export default {
  name: 'IctProjectForm',
  dicts: ['ict_project_first_type', 'ict_project_second_type', 'ict_project_attributive', 'ict_project_is_frame_supports', 'ict_project_project_status', 'ict_project_is_delivered', 'ict_project_implementation_progress', 'ict_project_business_progress', 'ict_project_is_middle_selection', 'ict_project_is_initial_test', 'ict_project_customer_side_progress', 'ict_project_partner_side_progress', 'ict_project_ifZ', 'ict_project_ifBigData', 'ict_project_customMode', 'ict_project_partnerMode', 'ict_project_isComplain', 'ict_project_isComplain', 'ict_project_industry_type'],
  data() {
    return {
      loading: false,
      form: {},
      id: this.$route.query.id,
      permission: {
        add: ['admin', 'ictManager', 'ictProject:add'],
        edit: ['admin', 'ictManager', 'ictProject:edit'],
        del: ['admin', 'ictManager', 'ictProject:del']
      },
      rules: {
      }
    }
  },
  created() {
    if (this.id) {
      this.loading = true
      this.getDetail(this.id)
      this.loading = false
    } else {
      this.initForm()
    }
  },
  methods: {
    cancelForm() {
      this.$router.go(-1)
    },
    submitForm(form) {
      this.loading = true
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.id) {
            this.toEdit(form)
          } else {
            this.toAdd(form)
          }
        } else {
          console.log('error submit!')
          return false;
        }
      })
      this.loading = false
    },
    toAdd(form) {
      crudIctProject.add(form).then(res => {
        if (res.msg === 'OK') {
          this.$notify.success({
            title: '添加成功'
          })
          this.$router.go(-1)
        }
      }).catch(e => {
        this.$notify.error({
          title: '添加失败' + e
        })
      })
    },
    toEdit(form) {
      crudIctProject.edit(form).then(res => {
        if (res.msg === 'OK') {
          this.loading = false
          this.$notify.success({
            title: '更新成功'
          })
          this.$router.go(-1)
        }
      }).catch(e => {
        this.$notify.error({
          title: '更新失败' + e
        })
      })
    },
    getDetail(id) {
      // this.loading = true
      crudIctProject.get(id).then(res => {
        this.form = res.data
      }).catch(e => {
        console.log(e)
      })
      // this.loading = false
    },
    initForm() {
      this.form = defaultForm
    },
    // 获取数据前设置好接口地址
    [CRUD.HOOK.beforeRefresh]() {
      return true
    },
    // 获取数据后对数据进行二次处理
    [CRUD.HOOK.afterRefresh]() {

    }
  }

}
</script>

<style lang="scss" scoped>
</style>
